/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * <p>Project: jse2302 - TreeSetDemo
 * <p>Powered by webrx On 2023-06-25 16:17:50
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class TreeSetDemo {
    public static void main(String[] args) {
        Set<Integer> ts1 = new TreeSet<>((a, b) -> b - a);
        ts1.add(6);
        ts1.add(3);
        ts1.add(4);
        ts1.add(40);
        ts1.add(14);
        ts1.add(1);
        System.out.println(ts1);

        TreeSet<String> ts2 = new TreeSet<>((a, b) -> b.compareTo(a));
        ts2.add("java");
        ts2.add("c");
        ts2.add("go");
        ts2.add("javascript");
        System.out.println(ts2);

        TreeSet<Book> ts3 = new TreeSet<>((a, b) -> b.getId() - a.getId());
        ts3.addAll(List.of(
                new Book(10, "《java入门》"),
                new Book(10, "《java入门》"),
                new Book(20, "《mysql入门》"),
                new Book(50, "《vue入门》")
        ));

        System.out.println(ts3);
    }
}
